package org.chengn.level_middle.context1657;

import java.util.Arrays;

public class Context1657 {
    public boolean closeStrings(String word1, String word2) {
        if (word1.length() != word2.length()) return false;
        int[] l1 = getNumList(word1);

        int[] l2 = getNumList(word2);

        for (int i = 0; i < l1.length; ++i) {
            if ((l1[i] * l2[i] == 0) && (l1[i] + l2[i] != 0)) return false;
        }
        Arrays.sort(l1);
        Arrays.sort(l2);

        for (int i = 0; i < l1.length; ++i) {
            if (l1[i] != l2[i])return false;
        }

        return true;
    }

    int[] getNumList(String word) {
        int[] list = new int[26];
        for (int i = 0; i < word.length(); ++i) {
            char ch = word.charAt(i);
            list[(int)ch - 'a'] ++;
        }
        return list;

    }
}
